package jbeh;

import org.jbehave.core.annotations.BeforeScenario;
import org.jbehave.core.annotations.BeforeStories;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.jbehave.web.selenium.WebDriverProvider;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class BahnStartPage {

	public static final String HTTP_WWW_BAHN_DE = "http://www.bahn.de";
	WebDriverProvider driverProvider;
	WebDriver webdriver = null;

	@BeforeScenario
	public void before() {
		this.webdriver = driverProvider.get();
	}

	public BahnStartPage(WebDriverProvider driverProvider) {
		super();
		this.driverProvider = driverProvider;
	}

	@Given("Website "+"http://www.bahn.de")
	public void startSite() {
		webdriver.get(HTTP_WWW_BAHN_DE);
	}

	@When("From $from")
	public void from(String from) {
		WebElement we = webdriver
				.findElement(new By.ById("qf-departure-point"));
		we.sendKeys(from);
	};

	@When("To $to")
	public void to(String to) {
		WebElement we = webdriver.findElement(new By.ById(
				"qf-destination-point"));
		we.sendKeys(to);
	};

	@When("Suchen")
	public void suchen() {
		WebElement we = webdriver.findElement(new By.ByName(
				"qf.bahn.button.suchen"));
		we.click();
	};

	@Then("Auswahl der Reise")
	public void visible(String item) {
		Assert.assertTrue(webdriver.getPageSource().contains(item));
	}
}
